import {GET_ChatList,GET_ChatList_Type} from "../constans";
import {Dispatch} from "redux";
//引入socket.io事件
import {getChatList, IGetChatAns} from "../../network/socket/chatList";
import {showToast} from "../../components/MyToast/MyToast";

export interface GET_CharList_Action {
    type: GET_ChatList_Type,
    data: Array<any>
}

export type chatList_modifyAction = GET_CharList_Action

export const actionGetChatList = (uUid: string) => {
    return (dispatch: Dispatch) => {
        getChatList(uUid)
            .then(res => {
                const {code,data} = res as unknown as IGetChatAns
                if(code === 200){
                    dispatch<GET_CharList_Action>({
                        type: GET_ChatList,
                        data
                    })
                }
            })
            .catch(err => {
                showToast({type: 'fail',content: err.msg})
            })
    }
}